<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script src="./lib/vue.js"></script>
</body>

</html>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./lib/vue.js"></script>
</head>

<body>
  <div id="app">
    <h3>{{title.substr(0,2)+'...'}}</h3>
    <h1>{{showTitle(title)}}</h1>
    <h3>{{ title | showTitleFilter(6) }}</h3>
  </div>

  <script>
    // 全局过滤器
    // 过滤器中的回调函数的第1个参数，永远给定数据源中对应的数据
    Vue.filter('showTitleFilter', (value, len = 8) => {
      console.log(len);
      if (value.length <= len) return value;
      return value.substr(0, len) + '...'
    });

    let vm = new Vue({
      el: '#app',
      data: {
        title: '据悉，苏炳添还有个身份是暨南大学副教授。这位“跑得最快的大学教授”'
      },
      methods: {
        showTitle(title, len = 2) {
          // len = len || 2;
          if (title.length <= len) return title;
          return title.substr(0, len) + '...'
        }
      }
    })
  </script>
</body>

</html>